import java.util.Scanner;

public class Test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int q = in.nextInt();
        int[] arr = new int[n+1];
        long[] dp = new long[n+1];//防止溢出
        for(int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }

        //创建dp 数组
        for(int i = 1; i <= n; i++) {
            dp[i] = dp[i-1] + arr[i];
        }

        //查询
        while(q > 0) {
            int l = in.nextInt();
            int r = in.nextInt();
            System.out.println(dp[r] - dp[l-1]);
            q--;
        }
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int m = in.nextInt();
        int q = in.nextInt();

        int[][] arr = new int[n+1][m+1];
        long[][] dp = new long[n+1][m+1];

        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                arr[i][j] = in.nextInt();
            }
        }

        //创建dp 数组
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + arr[i][j];
            }
        }

        //查询
        while(q > 0) {
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int x2 = in.nextInt();
            int y2 = in.nextInt();
            System.out.println(dp[x2][y2] - dp[x1-1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1]);
            q--;
        }
    }

    public int pivotIndex(int[] nums) {
        int n = nums.length;
        long[] larr = new long[n];
        long[] rarr = new long[n];
        //前缀和数组
        for(int i = 1; i < n; i++) {
            larr[i] = larr[i-1] + nums[i-1];
        }

        //后缀数组
        for(int i = n-2; i >= 0; i--) {
            rarr[i] = rarr[i+1] + nums[i+1];
        }

        //中心下标
        for(int i = 0; i < n; i++) {
            if(larr[i] == rarr[i]) {
                return i;
            }
        }

        return -1;
    }

    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] larr = new int[n];
        int[] rarr = new int[n];

        larr[0] = 1;
        rarr[n-1] = 1;

        //前缀积
        for(int i = 1; i < n; i++) {
            larr[i] = larr[i-1] * nums[i-1];
        }

        //后缀积
        for(int i = n-2; i >= 0; i--) {
            rarr[i] = rarr[i+1] * nums[i+1];
        }

        int[] ans = new int[n];
        for(int i = 0; i < n; i++) {
            ans[i] = larr[i] * rarr[i];
        }

        return ans;
    }
}
